
<style>
.affix{top:10px;}
.head-style-list li,.editor-template-list li{cursor: pointer;}
.baomings-bulk-add {position:relative;padding: 10px;margin-bottom: 10px;border: 1px solid #dddddd;}
.item-delete{position: absolute;right:5px;top: 0px;font-size:20px;z-index:1;}
#maincontent{background: #Fcfcfc}
.form-control {
    background: #FFF;
    border-radius: 3px;
}
.hidePrice .item-price{display:none !important;}
.fa-plus-circle,.fa-minus-circle{font-size:18px;margin-left:10px;cursor:pointer;}
.pickup-addresses p:nth-child(1) .fa-minus-circle{display:none;}
.pricerule-bulk-add:nth-child(1) .fa-minus-circle{display:none;}
.pricerule-bulk-add{padding-left:30px;}
.form-inline .control-label {
    margin-bottom: 0;
    vertical-align: middle;
    width: 45px;
}
</style>

{{$this->Form->create('Reserve',array('id'=>'ReserveAddForm','role'=>'form'))}}
		
	<div class="tab-content" style="margin-bottom:50px;">
			
		<div role="tabpanel" class="tab-pane active" id="chi-info">
			
			<div class="form-group form-inline  text-center">			
				{{$this->Form->input('Order.出发地',array('class'=>'form-control text-center','value'=>$order['Order']['serialize_info']['出发地'],'div'=>false,'style'=>'width: 130px;','label'=>false,'placeholder'=>'出发地','required'=>'required'))}}  <->
				{{$this->Form->input('Order.目的地',array('class'=>'form-control text-center','value'=>$order['Order']['serialize_info']['目的地'],'div'=>false,'placeholder'=>'目的地','style'=>'width: 130px;','label'=>false,'required'=>'required'))}}
			</div>

			<div class="form-group  form-inline">
				<label class="control-label" for="ReserveSummary">日期</label>
					<input name="data[Order][日期]" class="form-control" required="required" type="date" id="OrderDate">
			</div>
			<div class="form-group  form-inline">
				<label class="control-label" for="ReserveSummary">车次</label>
					{{$this->Form->input('Order.车次',array('class'=>'form-control','type'=>'text','div'=>false,'required'=>'required','label'=>false,))}}
			</div>
			
			<div class="form-group">
				<label class="control-label" for="ReserveSummary">要求</label>
				{{$this->Form->input('Order.remark',array('class'=>'form-control','placeholder'=>'请备注上下铺，靠窗等要求','rows'=>'3','div'=>false,'required'=>'required','label'=>false,))}}
			</div>
		<div>                
       
        <fieldset>
        <div class="clearfix">
        	<?PHP foreach($datalist as $key => $item) {
      				$item = $item['Item']; if(!empty($item['name']) && empty($item['身份证'])) continue;
      			?>
	        <div class="baomings-bulk-add">
	        	<a class="item-delete" id="item-{{$item['id']}}" data-id="{{$item['id']}}">&times;</a>
				
				<div class="form-group form-inline">
					<div style="width:59%;padding-right:1%;display:inline-block;">
						<label class="control-label">姓 &nbsp; 名 </label>
						{{$this->MForm->input('Item.'.$key.'.name',array('div'=>false,'type'=>'text','style'=>'width: 120px;','required'=>'required','value'=> $item['name'],'label'=>false));}}
					</div>
					<div class="item-price" style="width:39%;display:inline-block;">
						<label class="control-label" style="width:35px;">类型</label>
						{{$this->MForm->input('Item.'.$key.'.类型',array('div'=>false,'options'=>array('成人票'=>'成人票','儿童票'=>'儿童票'),'value'=> $item['类型'],'label'=>false));}}
					</div>
				</div>
				<div class="form-group form-inline">
					<label class="control-label">身份证</label>					
					{{$this->MForm->input('Item.'.$key.'.身份证',array('div'=>false,'value'=> $item['身份证'],'required'=>'required','label'=>false));}}
				</div>
			</div>

			<?PHP } ?>
    	</div>
        </fieldset>     
		</div>
		<p style="margin-bottom: 10px;"><a  class="btn btn-default btn-sm bulk-add-new">+ 增加乘客</a></p>
		<p><br/></p>		
		</div>

		<div>
			{{template orders/order_consignee}}
		</div>
				
		<!--
		<div class="form-group">
			<label class="col-xs-3 control-label" for="ReserveAddress">有效时间</label>
			<div class="col-xs-9 controls form-inline">
				{{$this->Form->input('expired',array('class'=>'form-control','default'=>0,'div'=>false,'label'=>false,))}}
				<p>按开始结束时间生效</p>
			</div>
		</div>
						
			<div class="form-group">
				<label class="col-xs-3 control-label" for="WxStorefrontPriority">开始时间</label>
				<div class="col-xs-9 controls form-inline">
					{{$this->Form->input('started',array('class'=>'form-control','type'=>'datetime','dateFormat'=>'YMD','timeFormat'=>24,
					'monthNames'=> array(
						1=>'1月',2=>'2月',3=>'3月',4=>'4月',5=>'5月',6=>'6月',
						7=>'7月',8=>'8月',9=>'9月',10=>'10月',11=>'11月',12=>'12月',
					),
					'div'=>false,'label'=>false,))}}
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 control-label" for="WxStorefrontPriority">结束时间</label>
				<div class="col-xs-9 controls form-inline">
					{{$this->Form->input('ended',array('class'=>'form-control','type'=>'datetime','dateFormat'=>'YMD','timeFormat'=>24,
					'monthNames'=> array(
						1=>'1月',2=>'2月',3=>'3月',4=>'4月',5=>'5月',6=>'6月',
						7=>'7月',8=>'8月',9=>'9月',10=>'10月',11=>'11月',12=>'12月',
					),
					'div'=>false,'label'=>false,))}}
				</div>
			</div> -->
	
	
		<div class="form-group">
			<button class="btn btn-primary btn-lg {{if $is_mobile}}btn-block navbar-fixed-bottom{{/if}}" type="submit">
				预定火车票
			</button>
		</div>
	</div>
{{$this->Form->end()}}

<script>

$(function(){

	$('#ReserveHidePrice').click(function(){
		if(this.checked){
			$('#ReserveAddForm').addClass('hidePrice');
			$('#ReserveAddForm .item-price :input').each(function(){
				$(this).data('val',this.value);
				this.value = 0;
			})
		}
		else{
			$('#ReserveAddForm').removeClass('hidePrice');
			$('#ReserveAddForm .item-price :input').each(function(){
				$(this).val($(this).data('val'));
			})
		}	
	})
	
	$('#ReserveAddForm').data('submitCallback',function(request){
		if(request.ret == 0 && request.data.Reserve.id > 0) {
			showSuccessMessage('活动已成功{{if $current_action=='add'}}创建{{else}}修改{{/if}}，即将进入详情页');
			window.location = '/wx_activities/view/' + request.data.Reserve.id ;
		}
	});

	$(document).on('click','#price-rules .fa-plus-circle',function(){
		var clone = $(this).parents('.pricerule-bulk-add:first').clone();
        clone.find(':text').val('');
        clone.insertAfter( $(this).parents('.pricerule-bulk-add:first') );
        
        $('.pricerule-bulk-add').each(function(i){
        	$(this).find(':input').each(function(){
	            var name = $(this).attr('name');
	            //alert(name.replace(/\[\d*\]/,'[10]'));
	            $(this).attr('name',name.replace(/\[\d*\]/,'['+i+']'));
	        })
        });
	});
	$(document).on('click','.pricerule-bulk-add .fa-minus-circle',function(){		
        $(this).parents('.pricerule-bulk-add:first').remove();
    });

	$(document).on('click','.pickup-addresses .fa-plus-circle',function(){
	    var clone = $(this).parents('p:first').clone();
        clone.find('input').val('');
        clone.insertAfter( $(this).parents('p:first') );
        
        $('.pickup-addresses').find(':input').each(function(i){
            var name = $(this).attr('name');
            //alert(name.replace(/\[\d*\]/,'[10]'));
            $(this).attr('name',name.replace(/\[\d*\]/,'['+i+']'));
        });
        
	});
    $(document).on('click','.pickup-addresses .fa-minus-circle',function(){
        $(this).parents('p:first').remove();
    });
	
	$(document).on('click','.bulk-add-new',function(){
		var obj = $('.baomings-bulk-add:last');

		var newobj = obj.clone();newobj.find(':text').val('');
		newobj.insertAfter(obj);
		
		$('.baomings-bulk-add').each(function(i){
			$(this).find(':input').each(function(){
				var name = $(this).attr('name');
				//alert(name.replace(/\[\d*\]/,'[10]'));
				$(this).attr('name',name.replace(/\[\d*\]/,'['+i+']'));
			});
		});		
	})
	$(document).on('click','.item-delete',function(){
		if( $('.baomings-bulk-add').size() > 1 ){
			var id = $(this).data('id');
			if( id > 0 ) {
				if(confirm('请注意删除已添加项，可能影响已提交的数据，是否确认删除？')) {
					ajaxAction('/baomings/delete/'+id,null,null,function(request){
						if(request.ret == 0) {
							showSuccessMessage(request.msg);
							$('#item-'+id).remove();
						}
						else{
							showErrorMessage(request.msg);
						}
					});
				}
			}
			else{
				$(this).parents('.baomings-bulk-add').remove();	
			}
		}
		else{
			alert('项目至少要保留1个');		
		}		
	})
})
</script>